@extends('layouts.app')
@section('content')
    <div class="content">
        <a class="btn btn-info btn-sm" href="{{ redirect()->back()->getTargetUrl() }}"> 返回 </a>
        <br />
        <br />
        {!! form($form) !!}
    </div>
@endsection
@push('scripts')
    <script>
        $('.content').find('form').addClass('form-inline')
        $('.content').find('form').find('label').attr('style', 'width:120px;text-align:center')
        $('.form-group').attr('style', 'margin:10px 0px;')

        $('[for="top_category_id"]').parent().after('<br>');
        $('[for="first_category_id"]').parent().after('<br>');
        $('[for="name"]').parent().after('<br>');

        $('#top_category_id').on('change', function () {

            top_category_id = $(this).val()
            shop_id = {{ $shopId }}
            $.ajax({
                url: '{{ route('admin.good.select_category') }}',
                type: "GET",
                dataType:'json',
                data: {
                    top_category_id: top_category_id,
                    first_category_id:0,
                    shop_id : shop_id
                },
                success: function (re) {
                    $('#first_category_id').empty()
                    options = '';
                    for (var i = 0; i < re.length; i++) {
                        options += '<option value="' + re[i].id + '">' + re[i].name + '</option>'
                    }
                    $('#first_category_id').append(options)
                }
            });
        });
        
    </script>
@endpush
